<!-- 平板形式展现帖子 -->


<%@page pageEncoding="UTF-8"%>

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Iterator"%>
<%@page import="com.sxt.bbs.db.DB"%>
<%@page import="com.sxt.bbs.entity.Article"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.SQLException"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>

<%
	boolean logined = false;
	String adminLogined = (String) session.getAttribute("adminLogined");
	if (adminLogined != null && adminLogined.trim().equals("true")) {
		logined = true;
	}
%>

<%
	final int PAGE_SIZE = 4;
	int pageNo = 1;
	String strPageNo = request.getParameter("pageNo");
	if (strPageNo != null && !strPageNo.trim().equals("")) {
		pageNo = Integer.parseInt(strPageNo);
	} else {
		pageNo = 1;
	}

	if (pageNo <= 0) {
		pageNo = 1;
	}

	int totalPages = 0;

	List<Article> articles = new ArrayList<Article>();
	Connection conn = DB.getConn();

	Statement statCount = DB.createStat(conn);
	ResultSet rsCount = DB.excuteQuerey(statCount,
			"select count(*) from article where pid = 0");
	rsCount.next();
	int totalRecords = rsCount.getInt(1);

	totalPages = (totalRecords + PAGE_SIZE - 1) / PAGE_SIZE;

	if (pageNo > totalPages) {
		pageNo = totalPages;
	}
	Statement stat = DB.createStat(conn);
	int startPos = (pageNo - 1) * PAGE_SIZE;
	ResultSet rs = DB.excuteQuerey(stat,
			"select * from article where pid = 0 order by pdate desc limit "
					+ startPos + " , " + PAGE_SIZE);
	while (rs.next()) {
		Article articleTemp = new Article();
		articleTemp.initFromRS(rs);
		articles.add(articleTemp);
	}

	DB.close(rsCount);
	DB.close(statCount);
	DB.close(rs);
	DB.close(stat);
	DB.close(conn);
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0037)http://bbs.51cto.com/forum-133-1.html -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Java论坛 - 51CTO技术论坛_中国领先的IT技术社区</title>
<link rel="archives" title="51CTO技术论坛_中国领先的IT技术社区"
	href="http://bbs.51cto.com/archiver/" />
<link href="./page_style/global.css" rel="stylesheet" type="text/css" />
<link href="./page_style/map_menu.css" rel="stylesheet" type="text/css" />
<link href="./page_style/style.css" rel="stylesheet" type="text/css" />
<link href="./page_style/sidebar.css" rel="stylesheet" type="text/css" />
<style type="text/css"></style>

<link href="./page_style/art_master_top.css" rel="stylesheet"
	type="text/css" />
<style type="text/css"></style>

</head>
<body>

	<div class="first">
		<a href="http://bbs.51cto.com/" target="_blank" class="logo"><img
			src="./page_style/logo.jpg" /></a>
	</div>

	<div class="w960">
		<div class="row01z">
			<div class="wlgl">
				<div class="wlgl_tit">
					<h3 id="cdis">Java论坛</h3>
				</div>
				<div class="banz"></div>
			</div>
		</div>
		<div class="clear hr10"></div>
	</div>
	<div id="ad_plate"></div>
	<div class="tabbox">
		<div class="tab_z01">
			<a class="sd03 fl"
				href="http://bbs.51cto.com/forumdisplay.php?fid=133">全部主题</a>
		</div>
		<div class="fr" style="width:308px;">
			<div class="btnbox" id="newspecial">
				<a href="post.jsp" title="发新话题"> <img
					src="./page_style/newtopic_hov.gif" class="fr" />
				</a>
				<div id="newspecial_menu" style="display:none;" class="tw_float">
					<ul>
						<li><a href="post.jsp"><img
								src="./page_style/folder_s.gif" />发新话题</a></li>
					</ul>
				</div>
			</div>
		</div>
	</div>
	<div class="clear"></div>
	<div class="t_main" style="position:relative;">
		<div class="t_main01">
			<div class="t_header">
				<p class="t_author">作者</p>
				<p class="t_reply">回复/查看</p>
				<p class="t_lastPost">最后发表</p>
			</div>
		</div>
		<div class="trbg" china="主贴列表">
			<table width="100%" border="0" cellspacing="0" cellpadding="0"
				align="center" id="mytable">
				<tbody>

					<%
						for (Iterator<Article> it = articles.iterator(); it.hasNext();) {
							Article articleTemp = it.next();
					%>


					<tr>
						<td colspan="8" align="center" valign="middle" id="fjx"
							class="fjx"></td>
					</tr>
					<tr class="t_item">

						<%
							String url = request.getScheme() + "://"
										+ request.getServerName() + request.getServerPort();
								url += request.getContextPath();
								url += request.getServletPath();
								url += request.getQueryString() == null ? "" : ("?" + request
										.getQueryString());
								System.out.println(url);
						%>

						<%
						if(logined) {
						%>
						<td><a
							href="delete.jsp?id=<%=articleTemp.getId()%>&pid=<%=articleTemp.getPid()%>&from<%=url%>">DEL</a></td>
						<%
						}
						%>
						<td width="27" align="center" valign="middle"><a
							href="javascript:void(0)"></a></td>
						<td width="32" colspan="3" align="left" valign="middle"
							class="common"><span id="thread_1139316"> <a
								href="article_detail_flat.jsp?rootId=<%=articleTemp.getRootId()%>"
								target="_blank"><%=articleTemp.getTitle()%></a>
						</span></td>
						<td width="120" align="left" valign="middle" class="by"><a
							href="http://bbs.51cto.com/space-uid-9737346.html">程序_1011</a> <br />
							<%=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
						.format(articleTemp.getTimeStamp())%></td>
						<td width="70" align="left" valign="middle" class="td03"><a
							href="http://bbs.51cto.com/thread-1139316-1.html" target="_blank">348</a>
							<br /> 6437</td>
						<td width="130" align="left" valign="middle" class="by"><a
							href="http://bbs.51cto.com/space-username-doggiejohn.html">doggiejohn</a>
							<br /> 2015-06-17 20:30:13</td>
					</tr>

					<%
						}
					%>

				</tbody>
			</table>
		</div>
		<div class="clear"></div>
	</div>
	<div class="pagebox">
		<ul>
			<li><a href="article_flat.jsp?pageNo=<%=pageNo - 1%>">上一页</a></li>
			<li><a href="article_flat.jsp?pageNo=1">1</a></li>
			<li><a href="article_flat.jsp?pageNo=<%=pageNo + 1%>">下一页</a></li>
		</ul>
	</div>
	<div style="display:none"></div>
</body>
</html>